package cn.zye.msa;

import java.util.List;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class ImageViewAdapter extends BaseAdapter {
	private List<String> mImageIds = null;
	private Context mContext;

	public ImageViewAdapter(Context mContext, List<String> imageIDs) {
		super();
		this.mImageIds = imageIDs;
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mImageIds.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ImageView i = new ImageView(mContext);
		if (mImageIds.size() > 0) {
			if (mImageIds.get(position % mImageIds.size()).equals("3gp")) {
				i.setImageResource(R.drawable.video);
			} else if (mImageIds.get(position % mImageIds.size()).equals("amr")) {
				i.setImageResource(R.drawable.record);
			} else {
				i.setImageBitmap(BitmapFactory.decodeFile(mImageIds
						.get(position % mImageIds.size())));
			}
			i.setLayoutParams(new Gallery.LayoutParams(90, 60));// layout
			i.setScaleType(ImageView.ScaleType.FIT_XY);// set scale type
		}
		return i;
	}
}
